package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.service.MemberFootprintService;
import com.cskaoyan.market.db.domain.MarketFootprint;
import com.cskaoyan.market.db.domain.MarketFootprintExample;
import com.cskaoyan.market.db.mapper.MarketFootprintMapper;
import com.cskaoyan.market.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author TangHonghao
 * @since 2023/03/20 22:24
 */
public class MemberFootprintServiceImpl implements MemberFootprintService {
    @Override
    public List<MarketFootprint> selectFootprintByUserId(Integer uid) {
        SqlSession session = MyBatisUtil.getSession();
        MarketFootprintMapper marketFootprintMapper = session.getMapper(MarketFootprintMapper.class);
        MarketFootprintExample marketFootprintExample = new MarketFootprintExample();
        marketFootprintExample.or().andUserIdEqualTo(uid);
        List<MarketFootprint> marketFootprints = marketFootprintMapper.selectByExample(marketFootprintExample);
        session.commit();
        session.close();
        return marketFootprints;
    }

    @Override
    public List<MarketFootprint> selectFootprintByGoodsId(Integer gid) {
        SqlSession session = MyBatisUtil.getSession();
        MarketFootprintMapper marketFootprintMapper = session.getMapper(MarketFootprintMapper.class);
        MarketFootprintExample marketFootprintExample = new MarketFootprintExample();
        marketFootprintExample.or().andGoodsIdEqualTo(gid);
        List<MarketFootprint> marketFootprints = marketFootprintMapper.selectByExample(marketFootprintExample);
        session.commit();
        session.close();
        return marketFootprints;
    }

    @Override
    public List<MarketFootprint> selectFootprintAll() {
        SqlSession session = MyBatisUtil.getSession();
        MarketFootprintMapper marketFootprintMapper = session.getMapper(MarketFootprintMapper.class);
        MarketFootprintExample marketFootprintExample = new MarketFootprintExample();
        List<MarketFootprint> marketFootprints = marketFootprintMapper.selectByExample(marketFootprintExample);
        session.commit();
        session.close();
        return marketFootprints;

    }
}
